/*
 * Licensed under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.submarine.registry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.submarine.common.URL;

/**
 * @file org.submarine.registry.RegistryFactory.java
 *
 * 注册工厂类
 * 
 * @author gaojian
 * @created 2013-8-17 下午11:58:41
 * @version 0.0.1
 * @since 0.0.1
 * 
 */
public abstract class RegistryFactory {
	
	private static final Map<URL, AbstractRegistry> registryMap = new ConcurrentHashMap<URL, AbstractRegistry>();
	
	/**
	 * 
	 * 创建Registry
	 *
	 * @author gaojian
	 * @created 2013年8月25日 上午12:54:21
	 *
	 * @param url
	 * @return
	 */
	public AbstractRegistry createRegistry(URL url) {
		if (!registryMap.containsKey(url)) {
			registryMap.put(url, doCreateRegistry());
		}
		return registryMap.get(url);
	}
	
	/**
	 * 
	 * 具体实现类执行创建Registry
	 *
	 * @author gaojian
	 * @created 2013-8-19 上午11:40:13
	 *
	 * @return
	 */
	abstract protected AbstractRegistry doCreateRegistry();
}
